package com.yayo.mangement.exporter;

import com.yayo.mangement.authentication.annotations.ExcelExport;
import com.yayo.mangement.converter.UserConverter;
import com.yayo.mangement.iface.XlsxExporter;
import com.yayo.mangement.info.UserInfo;
import com.yayo.mangement.model.SysUser;
import com.yayo.mangement.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @UserExporter:
 * @author: Yayo
 * @date: 2020/7/22 9:58
 */
@ExcelExport(code = "user")
public class UserExporter implements XlsxExporter<UserInfo, UserContext> {

    @Autowired
    private SysUserService userService;

    @Autowired
    private UserConverter userConverter;
    @Override
    public List<UserInfo> export(UserContext context) {
        if(context != null){
            System.out.println(context.getAge());
            System.out.println(context.getUsername());
            System.out.println(context.getName());
        }

        List<SysUser> userList = userService.findAll();
        List<UserInfo> userInfoList = userList.stream().map(userConverter::do2info).collect(Collectors.toList());
        return userInfoList;
    }
}
